package com.weibo.host.severlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import com.weibo.common.BaseSeverlet;
import com.weibo.common.CommonUtil;
import com.weibo.host.service.HostService;
import com.weibo.host.service.imp.HostServiceImp;

public class HostSeverlet extends BaseSeverlet{
	private static Logger logger =  Logger.getLogger(HostSeverlet.class);
	@Override
	public void doService(HttpServletRequest request,
			HttpServletResponse response) {
		// TODO Auto-generated method stub
		try {
			HostService hostService = new HostServiceImp();
			String currentPage = request.getParameter("currentPage");
			if(currentPage==null||"".equals(currentPage)){
				currentPage = "1";
			}
			
			//获取游客列表
			List list = hostService.getHostList_ForVisitor(Integer.parseInt(currentPage)-1);
			request.setAttribute("hostList", list);
			
			//获取游客列表的总条目数
			int TotalPageNum = CommonUtil.getTotalPageNum(hostService.getHostTotalSize());
			request.setAttribute("currentPage", currentPage);
			request.setAttribute("totalPageNum", TotalPageNum);
			request.setAttribute("currentmenu", "博主资源");
			request.getRequestDispatcher("/visitors.jsp").forward(request, response);
		} catch (ServletException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			logger.error(e);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			logger.error(e);
		}
		
	}

}
